<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	</head>
	
	<body>
		<div class="breadcrumbs" id="breadcrumbs">
	
			<ul class="breadcrumb">
				<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
				<li>原题库</li>
				<li class="active">修改</li>
			</ul>
			
		</div>
		
		<div class="page-content">
			<div class="page-header">
				<h1>原题库
					<small>
					<i class="icon-double-angle-right"></i>
					修改				
					</small>					
				</h1>							 							
			</div> 
			<div class="row">
				<div class="col-xs-12">
					<form class="form-horizontal" onsubmit="return questionUpdate();" role="form" id="sysQuestionForm" name="question" method="post">
						
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">所属科目</label>
							<div class="col-sm-9">
							<select id="subjectId">
								<option value="1">语文</option>
								<option value="2">数学</option>
								<option value="3">英语</option>
							</select>
							</div>
						</div>
						
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">姓名</label>
							<div class="col-sm-5">
								<input type="text" readonly=""  id="name"  name="name" value="${question.student.name}" placeholder="姓名" required class="col-xs-10 col-sm-5" size="50" />
							</div>
						</div>
						
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">学校</label>
							<div class="col-sm-9">
							<select id="schoolId" >
							</select>
							</div>
						</div>
						
						
						
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">年级</label>
							<div class="col-sm-9">
							<select id="gradeId">
							</select>
							</div>
						</div>
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">班级</label>
							<div class="col-sm-9">
							<select id="classId">
							</select>
							</div>
						</div>
						
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">上传时间</label>
							<div class="col-sm-5">
							<input readonly="" type="text" class="col-xs-10 col-sm-5" id="form-input-readonly" value="<fmt:formatDate value="${question.createTime}" pattern="yyyy-MM-dd HH:mm"/>" />
							
							</div>
						</div>
						
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">状态</label>
							<div class="col-sm-5">
							<select id="status">
								<option value="1" <c:if test="${question.status==1}">selected</c:if>>未解决</option>
								<option value="2" <c:if test="${question.status==2}">selected</c:if>>已解决</option>
							</select>
							</div>
						</div>
						
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">图片</label>
							<div class="col-sm-5">
								<a  href="${ctx}/../upload/${question.url}" data-rel="colorbox">
										<img src="${ctx}/../upload/${question.url}" style="width: auto;height: 80px;"/>
								</a>
							</div>
						</div>
						
						
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">描述</label>
							<div class="col-sm-5">
								<textarea rows="10" cols="100" id="remark" name="remark">${question.remark}</textarea>
							</div>
						</div>
						
						
						
						<input name="id" value="${question.id}" id="id" type="hidden"/>
						<div class="clearfix form-actions">
							<div class="col-md-offset-3 col-md-9">
								<button class="btn btn-info" type="submit">
									<i class="icon-ok bigger-110"></i>提交
								</button>
							</div>
						</div>
						
					</form>		
				</div>
							
			</div>
		</div>
		
		<script type="text/javascript">
			function questionUpdate() {
					//alert($('#status').val());
					var datastr = new Object();
					datastr.id=$('#id').val();
					datastr.remark=$('#remark').val();
					datastr.status=$('#status').val();
	    			/* datastr.name = $('#name').val();
	    			datastr.phone = $('#phone').val();
	    			datastr.email = $('#email').val();
	    			datastr.openId = $('#openId').val();*/
	    			datastr.schoolId = $('#schoolId').val();
	    			datastr.gradeId = $('#gradeId').val();
	    			datastr.classId = $('#classId').val(); 
					var result = true;
					$.ajax({
    		        async: true,
    		        type:"POST",
    		        data:JSON.stringify(datastr),
    		        url: "${ctx}/sys/question/update",
    		        dataType: "json",
    		        headers : {  
                        'Content-Type' : 'application/json;charset=utf-8'  
                    },
	                    success : function(data) {
	                		if (data != undefined && data.status != undefined
	                				&& data.status.trim() == '0') {
	                			result = true;
	                			alert("保存成功！");
	                			//window.location.href = "${ctx}/sys/question/toUpdate/"+datastr.id;
	                		} else {
	                			result = false;
	                			alert(data.error);
	                		}
	                	},
	    			},"json");
				return false; 
			}
			
			 $(function(){
				 var schoolId = ${question.schoolId};
				 var gradeId = ${question.gradeId};
				 var classlId = ${question.classId};
				 $.ajax({
				        async: true,
				        type:"POST",
				        data:null,
				        url: "${ctx}/sys/tschool/listall",
				        dataType: "json",
				        success: function (data) {
				    	    if("success" == data.result){//成功
								if(data.list.length>0){
									for(var a=0;a<data.list.length;a++){
										if(schoolId == data.list[a].id ){
											$("#schoolId").prepend("<option selected = 'selected' value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}else{
											$("#schoolId").prepend("<option value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}
										
									}
								}else{
									
								}
				    	    }else{//失败
				    	    	alert("学校加载失败");
				    	    }
				        }
					},"json");
				 
				 $.ajax({
				        async: true,
				        type:"POST",
				        data:null,
				        url: "${ctx}/sys/tgrade/listall",
				        dataType: "json",
				        success: function (data) {
				    	    if("success" == data.result){//成功
								if(data.list.length>0){
									for(var a=0;a<data.list.length;a++){
										if(gradeId == data.list[a].id){
											$("#gradeId").prepend("<option selected='selected' value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}else{
											$("#gradeId").prepend("<option value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}
									}
								}else{
									
								}
				    	    }else{//失败
				    	    	alert("年级加载失败");
				    	    }
				        }
					},"json");
				 
				 $.ajax({
				        async: true,
				        type:"POST",
				        data:null,
				        url: "${ctx}/sys/tclass/listall",
				        dataType: "json",
				        success: function (data) {
				    	    if("success" == data.result){//成功
								if(data.list.length>0){
									for(var a=0;a<data.list.length;a++){
										if(classId == data.list[a].id){
											$("#classId").prepend("<option selected ='selected' value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}else{
											$("#classId").prepend("<option value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}
										
									}
								}else{
									
								}
				    	    }else{//失败
				    	    	alert("班级加载失败");
				    	    }
				        }
					},"json");
			 });
		</script>
	</body>


</html>